
use "*/Replication files/anes_timeseries_2012_slim_rresentment.dta", clear
merge 1:1 caseid using "*/Replication files/2012 validated/anes_timeseries_2012_voteval.dta"
svyset [pw= weight_ftf]

rename vote validated_vote

gen satis = cses_satisdem
replace satis = satis-4
replace satis = . if satis<1
revrs satis, replace

* Racial resentment, coded so higher values are more resentful
gen racial_resentment1 = resent_workway
replace racial_resentment1 = racial_resentment1-4
replace racial_resentment1 = . if racial_resentment1<1
revrs racial_resentment1 , replace

gen racial_resentment2 = resent_slavery
replace racial_resentment2 = racial_resentment2-4
replace racial_resentment2 = . if racial_resentment2<1

gen racial_resentment3 = resent_deserve
replace racial_resentment3 = racial_resentment3-5
replace racial_resentment3 = . if racial_resentment3<1

gen racial_resentment4 = resent_try
replace racial_resentment4 = racial_resentment4-4
replace racial_resentment4 = . if racial_resentment4<1
revrs racial_resentment4 , replace

corr racial_resentment1 racial_resentment2 racial_resentment3 racial_resentment4 
alpha racial_resentment1 racial_resentment2 racial_resentment3 racial_resentment4 , gen(racial_resentment)

* Post-election vote report
gen vote_post = presvote2012_x
recode vote_post (-9=.) (-6=.) (-2=.) (1=0) (2=1) (5=.) // Democrats are coded as 
gen winner_post = vote_post
recode winner_post (0=1) (1=0)

* Pre-election vote
gen vote = prevote_intpreswho
recode vote (1=.) (2=.) (3=.) (4=0) (5=1) (6=.)
gen winner = vote
recode winner (0=1) (1=0)

* Income
gen income	= incgroup_prepost_x
recode income (1 = .) (2=.)
replace income =incgroup_prepost_x - 2

* Age
gen age = dem_age_r_x
replace age = . if age<17

* Education
gen edu = dem_edu
recode edu (1=.)
replace edu = edu - 2
recode edu (1=1) (2=1) (3=1) (4=1) (5=2) (6=2) (7=2) (8=2) (9=3) (11=4) ///
	(10=5) (12=5) (13=6) (13=7) (14=7) (15=7) (16=7) (90=3) (95=.) (-9=.)
label define edulab 1 "1. 8 grades or less" 2 "2. 9-12 grades" 3 "3. High school" ///
	4 "4. HS + non-academic training" 5 "5. Some college" 6 "7. BA" 7 "7. Advanced" , replace
label values edu edulab

* Race of respondent
gen white = 1 if dem_racecps_white == 2
replace white = 0 if dem_racecps_white != 2 & dem_racecps_white != .

gen black = 1 if dem_racecps_black == 2
replace black = 0 if dem_racecps_black != 2 & dem_racecps_black != .

gen blackwhite = .
replace blackwhite = 0 if black == 1
replace blackwhite = 1 if white == 1

gen race = 2 if blackwhite == 0
replace race = 1 if blackwhite == 1
label define blackwhitelab 0 "Black" 1 "White"  , replace
label values blackwhite blackwhitelab

* Gender
gen gender = gender_respondent_x
recode gender (-9=.) (3=.)
gen female = gender -1 
label define genderlab 0 "0. Male" 1 "1. Female" , replace
label values female genderlab

* Interest
gen interest = interest_following
recode interest (1=.) (2=.)
replace interest = interest-2
revrs interest , replace

* Econmic perceptions
gen natl_econ = econ_ecpast_x
replace natl_econ = natl_econ - 2
drop if natl_econ <1
revrs natl_econ, replace

* Ideology
gen ideology = libcpre_self if libcpre_self
replace ideology = . if ideo<4
replace ideology = ideology-3

* Sample size for data by mode
order satis racial_resentment winner ideology interest natl_econ income age edu female 
egen hasmiss = rowmiss(satis-female)
egen sumup = rowtotal(satis-female)
replace sumup = . if hasmiss
tab mode if race==1 & vote_post==vote & sumup!=.

set more off
* Table B.5 column 1
reg satis c.racial_resentment##winner ideology interest natl_econ income age ///
	edu female   if race==1 & vote_post==vote & validated_vote==1

* Table B.5  column 2
reg satis c.racial_resentment##winner ideology interest natl_econ income age ///
	edu female   if race==1 & vote_post==vote & mode==1

* Table B.5  column 3
reg satis c.racial_resentment##winner##i.mode ideology interest natl_econ ///
	income age edu female   if race==1 & vote_post==vote

* Table C.6 column 1
ologit satis c.racial_resentment##winner ideology interest natl_econ income ///
	age edu female   if race==1 & vote_post==vote & validated_vote==1

* Table C.6  column 2
ologit satis c.racial_resentment##winner ideology interest natl_econ income ///
	age edu female   if race==1 & vote_post==vote & mode==1

* Table C.6  column 3
ologit satis c.racial_resentment##winner##i.mode ideology interest natl_econ ///
	income age edu female   if race==1 & vote_post==vote

